<template>
	<view class="content">
		<u-navbar safeAreaInsetTop placeholder fixed autoBack>
			<view class="u-nav-slot color_ling text_weight" slot="center">
				服务订单
			</view>
			<view class="u-nav-slot text_a color_san" slot="right">
				<text @click="refund">退款</text>
			</view>
		</u-navbar>
		<u-sticky bgColor="#fff">
			<u-tabs :list="list1" lineColor="rgba(243, 39, 28, 1)" :current="currenttabtow" @click="clicktabtow"
				:activeStyle="{
				    color: '#000000',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}" :inactiveStyle="{
				            color: 'rgba(102, 102, 102, 1)',
							fontWeight: 'bold',
				            transform: 'scale(1)'
				        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;"></u-tabs>
		</u-sticky>
		<view class="padding_lrb">
			<view class="ffffff padding border_2 margin_top" v-for="(item,index) in list.data" :key="item.id"
				@click="goOrderInfo(item.id)">
				<view class="flexbetween">
					<view class="flexleft">
						<view class="number margin_right2 yihang">订单编号：{{item.order_no}}</view>
					</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==-1">已取消</view>
					<view class="hongsetext" style="color: rgba(255, 168, 0, 1);" v-show="item.state==1">待付款</view>
					<view class="hongsetext" style="color: rgba(255, 0, 0, 1);" v-show="item.state==3">待服务</view>
					<view class="hongsetext" style="color: rgba(243, 39, 28, 1);" v-show="item.state==4">服务中</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==5">待评价</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==6">已完成</view>
					<view class="hongsetext" style="color: rgba(19, 196, 99, 1);" v-show="item.state==8">已退款</view>
				</view>
				<view class="flexbetween xiahuax margin_top">
					<view class="shilitu">
						<image :src="item.service_image_text" mode=""></image>
					</view>
					<view class="" style="width: 74%;">
						<view class="yihang text_zi">{{item.service_name}}</view>
						<view class="flexbetween margin_top5">
							<view class="qianshu">¥{{item.total_price}}</view>
							<view class="shuliang">X1</view>

						</view>
					</view>
				</view>
				<!-- 所有按钮 -->
				<view class="flexright margin_top">
					<view class="huisebtn" @click.stop="enterChat(item)">联系客户</view>
					<view class="huangsebtn margin_left3" v-show="item.can_commentlist" @click.stop="estimate(item.id)">
						查看评价</view>
					<view class="huangsebtn margin_left3" v-show="item.can_deliver"
						@click.stop="atonceService(item.id)">立即服务</view>
					<view class="huisebtn margin_left3" v-show="item.can_del" @click.stop="deletorder(item.id)">删除订单
					</view>
				</view>
			</view>
			<view class="flexcenter placeholderBoxTop" v-if="!list.data.length">
				<image class="placeholderBox" src="/static/placeholderimg.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				currenttabtow: 0, //0全部，1待付款，2待服务，3服务中，4已服务
				list1: [{
						name: '待服务',
					},
					{
						name: '服务中',
					},
					{
						name: '已服务',
					}
				],
				page: 1,
				limit: 12,
				user_id: uni.getStorageSync("user_id"),
				list: {
					data: []
				},
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			init(isPage, page) {
				let _this = this;
				let obj = {
					"0": 3,
					"1": 4,
					"2": 5,
				}
				httpRequest.request("/api/shop.service_order/orderlist", 'GET', {
					page: page || 1,
					limit: _this.limit,
					state: obj[_this.currenttabtow],
				}, false, false, true).then(res => { //我的订单接口
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},

			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page)
			},
			// 进入聊天
			enterChat(item) {
				if (this.user_id == item.user_id) {
					httpRequest.toast("不能和自己聊天哦！");
					return false
				}
				let data = {
					firend_id: item.userinfo.id,
					friend_name: item.userinfo.nickname,
					firend_avatar_text: item.userinfo.avatar
				}
				uni.navigateTo({
					url: "/pages/chat/chat?msg=" + encodeURIComponent(JSON.stringify(data))
				})
			},
			estimate(id) { //查看评价
				uni.navigateTo({
					url: "/pages_mine/allEval?type=2&id=" + id
				})
			},
			atonceService(id) {
				httpRequest.modal('提示', '确定开始服务吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/shop.service_order/deliver', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			deletorder(id) { //删除订单
				httpRequest.modal('提示', '确定删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('/api/shop.service_order/del', 'POST', {
							order_id: id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg);
							if (res.code == 1) {
								this.init()
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			goOrderInfo(id) { //订单详情
				uni.navigateTo({
					url: "/pages_mine/serviceOrderInfo?id=" + id
				})
			},
			clicktabtow(e) {
				this.currenttabtow = e.index;
				this.init()
			},
			refund() {
				uni.navigateTo({
					url: "/pages_mine/serviceRefundOrder"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep.u-tabs__wrapper__nav__item {
		flex: 1 !important;
		white-space: nowrap;
	}

	.imgShop {
		width: 26.62rpx;
		height: 24rpx;

	}

	.fuzhi {
		margin: 0rpx 30rpx 30rpx 30rpx;
	}

	.dan {
		width: 80vw;
		padding: 64rpx 40rpx 0rpx 40rpx;
	}

	.wuliu {
		font-size: 40rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.zhongtong {

		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #000000;
		padding: 34rpx 82rpx;
		border: 1rpx solid rgba(223, 223, 223, 1);
		border-radius: 10rpx;
		margin: 87rpx 0rpx 0rpx 0rpx;
	}

	.copy {
		padding: 25rpx 150rpx;
		border-radius: 51rpx;
		background-color: RGBA(225, 159, 83, 1);
		margin-top: 109rpx;
		color: #fff;
	}

	.text_zi {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.number {
		width: calc(100vw - 72rpx - 140rpx);
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.nostrongtext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.baise {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		margin: 12rpx 0rpx;
	}

	.huangsebtn {
		border: 2rpx solid rgba(243, 39, 28, 1);
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: rgba(243, 39, 28, 1);
	}

	.huisebtn {
		border: 2rpx solid #666666;
		width: 170rpx;
		height: 67rpx;
		display: flex;
		border-radius: 120rpx;
		align-items: center;
		justify-content: center;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.ershisi {
		font-size: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.xiahuax {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, .1);
	}

	.shuliang {
		font-size: 26rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: rgba(243, 39, 28, 1);
	}

	.qianshu {
		font-size: 30rpx;
		font-family: DIN Next LT Pro-Bold, DIN Next LT Pro;
		font-weight: bold;
		color: rgba(243, 39, 28, 1);
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.shilitu {
		width: 134rpx;
		height: 128rpx;
		border-radius: 14rpx;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}
	}

	.lvsetext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #00C058;
	}

	.huangsetext {
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: RGBA(255, 117, 16, 1);
	}

	.hongsetext {
		width: 72rpx;
		min-width: 72rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: RGBA(255, 117, 16, 1);
	}

	.marginleft3 {
		margin-left: 30rpx;
	}
</style>